package com.easysoft.framework.action;

import com.easysoft.framework.beans.Page;
import com.easysoft.framework.logs.model.SysLogsQuery;
import com.easysoft.framework.logs.model.SysLogsView;
import com.easysoft.framework.logs.service.SysLogsService;
import com.easysoft.framework.menu.model.SysMenuQuery;
import com.easysoft.framework.menu.model.SysMenuView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Created by try on 2017/7/5.
 */
@RestController
@RequestMapping(value = SystemLogsAction.BASE_VIEW)
public class SystemLogsAction {
    public static final String BASE_VIEW = "/logs";
    private final static Logger logger = LoggerFactory.getLogger(SystemLogsAction.class);

    @Autowired
    @Qualifier("service.SysLogsService")
    private SysLogsService sysLogsService;

    /**
     * m
     * 日志列表
     *
     * @param page
     * @param query
     * @return
     */
    @RequestMapping(value = "/listLogs", method = {RequestMethod.POST, RequestMethod.GET})
    public ModelAndView listLogs(Page page, SysLogsQuery query) {

        logger.info("Call SystemLogsAction.listLogs({},{})", page.toString(), query.toString());

        List<SysLogsView> listLogs = sysLogsService.selectSysLogsByPage(page, query);

        ModelAndView mv = new ModelAndView(BASE_VIEW + "/listLogs");
        mv.addObject("page", page); // 返回分页
        mv.addObject("query", query);// 查询条件
        mv.addObject("listLogs", listLogs); // 返回查询结果集
        return mv;
    }


}
